
import java.util.ArrayDeque;


/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Moshe
 */
public class SearchResultsProvider {

   private ArrayDeque<SearchResultsItem> resultsQue;
   private final Object syncObject;
   public static final SearchResultsProvider Instance = new SearchResultsProvider();

    private SearchResultsProvider() {
        this.resultsQue = new ArrayDeque<SearchResultsItem>();
        this.syncObject = new Object();
    }

     public void addResults(int bestGrade, BitVector bestVec, long elapsedTime, long nodesCount, boolean isHC)
    {
         synchronized(this.syncObject)
         {
            this.resultsQue.add(new SearchResultsItem(bestGrade, bestVec, elapsedTime, nodesCount, isHC));
            this.syncObject.notify();
         }
    }

    public SearchResultsItem getResult()
    {
        synchronized(this.syncObject)
        {
            /*try {
                if (this.resultsQue.isEmpty()) {
                    this.syncObject.wait();
                }
            }
            catch (InterruptedException ex) {
            }*/
            return this.resultsQue.poll();
        }
    }

    public SearchResultsItem getLastResult()
    {
        synchronized(this.syncObject)
        {
            return this.resultsQue.getLast();
        }
    }

    public void ClearQue()
    {
        synchronized(this.syncObject)
        {
            this.resultsQue.clear();
        }

    }

}
